#ifndef System_H
#define System_H

#include <QObject>
#include <QTimer>
#include <QString>
#include <QVariantMap>

class System : public QObject
{
    Q_OBJECT

    Q_PROPERTY(QString osName READ osName NOTIFY osNameChanged)
    Q_PROPERTY(QString cpuModel READ cpuModel NOTIFY cpuModelChanged)
    Q_PROPERTY(int cpuCoreCount READ cpuCoreCount NOTIFY cpuCoreCountChanged)
    Q_PROPERTY(double cpuUsage READ cpuUsage NOTIFY cpuUsageChanged)
    Q_PROPERTY(qint64 totalMemory READ totalMemory NOTIFY totalMemoryChanged)
    Q_PROPERTY(qint64 freeMemory READ freeMemory NOTIFY freeMemoryChanged)
    Q_PROPERTY(QString diskUsage READ diskUsage NOTIFY diskUsageChanged)
    Q_PROPERTY(QString networkInfo READ networkInfo NOTIFY networkInfoChanged)
    Q_PROPERTY(QString machineId READ machineId NOTIFY machineIdChanged)
    Q_PROPERTY(QString softwareVersion READ softwareVersion NOTIFY softwareVersionChanged)
    Q_PROPERTY(QString machineType READ machineType NOTIFY machineTypeChanged)

public:
    Q_INVOKABLE bool checkSerialNumber(const QString& serialNumber);
    Q_INVOKABLE QString getDeadLine(const QString& serialNumber);
    Q_INVOKABLE bool saveSerialNumber(const QString& number, const QString& name);
    Q_INVOKABLE QString getSerialNumber();
    Q_INVOKABLE bool saveParam(const QString& param, const QString& value, const QString& name);
    Q_INVOKABLE QString getParam(const QString& param);

    explicit System(QObject *parent = nullptr);
    QString osName() const;
    QString cpuModel() const;
    int cpuCoreCount() const;
    double cpuUsage() const;
    qint64 totalMemory() const;
    qint64 freeMemory() const;
    QString diskUsage() const;
    QString networkInfo() const;
    QString machineId() const;
    QString softwareVersion() const;
    QString machineType() const;
    QString seq();

public slots:
    void updateSystem();

signals:
    void osNameChanged();
    void cpuModelChanged();
    void cpuCoreCountChanged();
    void cpuUsageChanged();
    void totalMemoryChanged();
    void freeMemoryChanged();
    void diskUsageChanged();
    void networkInfoChanged();
    void machineIdChanged();
    void softwareVersionChanged();
    void machineTypeChanged();
    void seqChanged();

private:
    void updateOSInfo();
    void updateCPUInfo();
    void updateMemoryInfo();
    void updateDiskInfo();
    void updateNetworkInfo();
    void updateseq();

    QString m_osName;
    QString m_cpuModel;
    int m_cpuCoreCount = 0;
    double m_cpuUsage = 0.0;
    qint64 m_totalMemory = 0;
    qint64 m_freeMemory = 0;
    QString m_diskUsage;
    QString m_networkInfo;
    QString m_machineId;
    QString m_machineType;


    bool m_firstSample = true;

    QTimer *m_timer;
};

#endif // System_H
